function [ps_start]=parse_cond_starts_vs(ps_raw,min_dur,refract_time,start_or_end)

ps_start_ind=[];
ps_end_ind=[];

ps_raw(end)=0;

if ps_raw(1)==1
    for ind=1:length(ps_raw)
        if ps_raw(ind)==0
            ps_raw(1:ind)=0;
            break
        end
    end
end



ps_start_ind=find(diff(ps_raw)==1);
ps_end_ind=find(diff(ps_raw)==-1);

cnt=0;
while cnt<length(ps_start_ind)-1
    cnt=cnt+1;
    if ps_start_ind(cnt+1)-ps_end_ind(cnt)<refract_time
        ps_start_ind=ps_start_ind([1:cnt cnt+2:end]);
        ps_end_ind=ps_end_ind([1:cnt-1 cnt+1:end]);
        cnt=cnt-1;
    end
end


ps_ind_mindur=(ps_end_ind-ps_start_ind)>min_dur;
ps_start_ind=ps_start_ind(ps_ind_mindur);
ps_end_ind=ps_end_ind(ps_ind_mindur);

ps_ind_refract=logical([1 ((ps_start_ind(2:end)-ps_end_ind(1:end-1))>refract_time)']);
if start_or_end==1;
    ps_start=ps_start_ind(ps_ind_refract)*10;
elseif start_or_end==2;
    ps_start=ps_end_ind(ps_ind_refract)*10;
end

